
package galcon.visuals.components;

import galcon.utils.Circle;
import galcon.utils.Constants;
import galcon.utils.Drawable;
import java.awt.Color;
import java.awt.Graphics;

public class Planet implements Drawable
{
    protected Circle circle;
    protected int ownerID, numships, productionRate;
    protected Color color;
    
    public Planet (Circle circle, int ownerID, int productionRate) {
        this.circle = circle;
        this.ownerID = ownerID;
        this.productionRate = productionRate;
        this.numships = 0;
        color = Color.WHITE;
    }
    
    public void setCircle (Circle circle) {
        this.circle = circle;
    }
    
    public void setOwnerID (int ownerID) {
        this.ownerID = ownerID;
    }
    
    public void setColor (Color color) {
        this.color = color;
    }
    
    public void setProductionRate (int productionRate) {
        this.productionRate = productionRate;
    }
    
    public void setShips (int numships) {
        this.numships = numships;
    }
    
    public Circle getCircle() {
        return circle;
    }
    
    public int getOwnerID() {
        return ownerID;
    }
    
    public Color getColor() {
        return color;
    }
    
    public int getProductionRate() {
        return productionRate;
    }
   
    public int getShips() {
        return numships;
    }

    public void addShips (int add) {
        this.numships += add;
    }
    
    public void subtractShips (int sub) {
        this.numships -= sub;
    }

    public void draw (Graphics g) {
        g.setColor (color);
        int radius = circle.getRadius(), x = circle.getPoint().getX(), y = circle.getPoint().getY();
        g.fillOval (x - radius, y - radius, 2 * radius, 2 * radius);
        
        g.setColor (Constants.TEXT_COLOR);
        g.setFont (Constants.TEXT_FONT);
        g.drawString (String.valueOf (numships), x - Constants.FONT_SIZE / 2, y + Constants.FONT_SIZE / 2);
    }

    public Planet clone(){
        Planet toReturn = new Planet(this.circle.clone(), this.ownerID, this.productionRate);
        toReturn.numships = this.numships;
        return toReturn;
    }

    public boolean equals(Object obj){
        if(obj instanceof Planet){
            if(((Planet)obj).getCircle().equals(this.circle)){
                return true;
            }
        }
        return false;
    }

    public String toString(){
        String result = "";
        result += "Planet: OwnerID: " + this.getOwnerID() + " Ships: " + this.getShips() + '\n';
        result += this.circle.toString() + '\n';
        return result;
    }
}
